
public class 轉型效能研究 {

	public static int parseInt(String s) {
		int i;
		int mul = 10;
		int value = s.charAt(s.length()-1)-48;
		
		for(i=s.length()-2;i>=0;i--) {
			value += (s.charAt(i)-48)*mul;
			mul *= 10;
		}
		
		return value;
	}
	
	public static void main(String[] args) {
		int i,v = 0;
		long begin,elapsed;
		String s = "123456789"; 
		
		begin = System.currentTimeMillis();
		for(i=0;i<10000000;i++) {
			v = parseInt(s);
		}
		elapsed = System.currentTimeMillis() - begin;
		System.out.println("自製int轉型耗費 "+elapsed+"ms");
		System.out.println(v);
		
		begin = System.currentTimeMillis();
		for(i=0;i<10000000;i++) {
			v = Integer.parseInt(s);
		}
		elapsed = System.currentTimeMillis() - begin;
		System.out.println("內建int轉型耗費 "+elapsed+"ms");
		System.out.println(v);
	}

}
